package com.zhaowei.codingintervierguide.stackandqueue;

import java.util.AbstractQueue;
import java.util.Queue;
import java.util.Stack;

public class ReverseStack {

    public static Integer getAndRemoveLastElement(Stack<Integer> stack) {
        if (!stack.isEmpty()) {
            Integer value = stack.pop();
            if (stack.isEmpty()) {
                return value;
            } else {
                Integer temp = getAndRemoveLastElement(stack);
                stack.push(value);
                return temp;
            }
        }
        return null;
    }

    public static Stack<Integer> reverseStack(Stack<Integer> stack) {
        if (stack.isEmpty()) {
            return null;
        }
        Integer value = getAndRemoveLastElement(stack);
        reverseStack(stack);
        stack.push(value);
        return stack;
    }

    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<>();
        stack.push(2);
        stack.push(4);
        stack.push(3);
        stack.push(5);
        System.out.println(stack);
        System.out.println(reverseStack(stack));


    }
}
